package com.jinmdz.fmis.mapper.mapper.provider;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;
import com.jinmdz.fmis.mapper.entity.CremationFurnaceViewEntity;

/**
 * 火化炉炕面连接开关关联表Provider
 * 
 * @author generator
 * @date 2020-08-23 18:11
 */
public class CremationFurnaceViewProvider {

    /**
     * 增加CremationFurnaceView
     * 
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-08-23 18:11
     */
    public String insertCremationFurnaceView(@Param("entity") CremationFurnaceViewEntity entity) {
        return new SQL() {
            {
                INSERT_INTO(" cremation_furnace_view ");

                if (entity.getDeleted() != null) {
                    VALUES(" deleted ", " #{entity.deleted,jdbcType=TINYINT} ");
                }

                VALUES(" business_code ", " #{entity.businessCode,jdbcType=VARCHAR} ");
                VALUES(" cremation_id ", " #{entity.cremationId,jdbcType=INTEGER} ");
                VALUES(" furnace_id ", " #{entity.furnaceId,jdbcType=INTEGER} ");
                VALUES(" camera_id ", " #{entity.cameraId,jdbcType=INTEGER} ");
                VALUES(" process_state_code ", " #{entity.processStateCode,jdbcType=TINYINT} ");
                VALUES(" open_time ", " #{entity.openTime,jdbcType=TIMESTAMP} ");
                VALUES(" close_time ", " #{entity.closeTime,jdbcType=TIMESTAMP} ");
                VALUES(" funeral_parlour_code ", " #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                VALUES(" create_user_id ", " #{entity.createUserId,jdbcType=INTEGER} ");

                if (entity.getUnmodified() != null) {
                    VALUES(" unmodified ", " #{entity.unmodified,jdbcType=TINYINT} ");
                }

                VALUES(" modified_user_id ", " #{entity.modifiedUserId,jdbcType=INTEGER} ");
                VALUES(" version ", " unix_timestamp(now()) ");
            }
        }.toString();
    }

    /**
     * 修改CremationFurnaceView
     * 
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-08-23 18:11
     */
    public String updateCremationFurnaceView(@Param("entity") CremationFurnaceViewEntity entity) {
        return new SQL() {
            {
                UPDATE(" cremation_furnace_view ");

                if (entity.getDeleted() != null) {
                    SET(" deleted = #{entity.deleted,jdbcType=TINYINT} ");
                }

                SET(" business_code = #{entity.businessCode,jdbcType=VARCHAR} ");
                SET(" cremation_id = #{entity.cremationId,jdbcType=INTEGER} ");
                SET(" furnace_id = #{entity.furnaceId,jdbcType=INTEGER} ");
                SET(" camera_id = #{entity.cameraId,jdbcType=INTEGER} ");
                SET(" process_state_code = #{entity.processStateCode,jdbcType=TINYINT} ");
                SET(" open_time = #{entity.openTime,jdbcType=TIMESTAMP} ");
                SET(" close_time = #{entity.closeTime,jdbcType=TIMESTAMP} ");
                SET(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");

                if (entity.getUnmodified() != null) {
                    SET(" unmodified = #{entity.unmodified,jdbcType=TINYINT} ");
                }

                SET(" modified_user_id = #{entity.modifiedUserId,jdbcType=INTEGER} ");
                SET(" version = unix_timestamp(now()) ");
                WHERE(" id = #{entity.id,jdbcType=INTEGER} ");
                WHERE(" unmodified = 0 ");
                WHERE(" version = #{entity.version,jdbcType=INTEGER} ");
            }
        }.toString();
    }

    /**
     * 查询CremationFurnaceView列表
     * 
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-08-23 18:11
     */
    public String listCremationFurnaceView(@Param("entity") CremationFurnaceViewEntity entity) {
        return new SQL() {
            {
                StringBuilder builder = new StringBuilder();
                builder.append(" id,deleted,business_code,cremation_id,furnace_id,camera_id,process_state_code,open_time,close_time,funeral_parlour_code,create_user_id,gmt_create,unmodified,modified_user_id,gmt_modified,version ");
                SELECT(builder.toString());
                FROM(" cremation_furnace_view ");

                if (entity.getBusinessCode() != null) {
                    WHERE(" business_code = #{entity.businessCode,jdbcType=VARCHAR} ");
                }

                if (entity.getCremationId() != null) {
                    WHERE(" cremation_id = #{entity.cremationId,jdbcType=INTEGER} ");
                }

                if (entity.getFurnaceId() != null) {
                    WHERE(" furnace_id = #{entity.furnaceId,jdbcType=INTEGER} ");
                }

                if (entity.getCameraId() != null) {
                    WHERE(" camera_id = #{entity.cameraId,jdbcType=INTEGER} ");
                }

                if (entity.getProcessStateCode() != null) {
                    WHERE(" process_state_code = #{entity.processStateCode,jdbcType=TINYINT} ");
                }

                if (entity.getOpenTime() != null) {
                    WHERE(" open_time = #{entity.openTime,jdbcType=TIMESTAMP} ");
                }

                if (entity.getCloseTime() != null) {
                    WHERE(" close_time = #{entity.closeTime,jdbcType=TIMESTAMP} ");
                }

                if (entity.getFuneralParlourCode() != null) {
                    WHERE(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                }

            }
        }.toString();
    }
}